package com.huihui.activity;

import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import com.huihui.R;
import com.huihui.base.BaseActivity;
import com.huihui.network.base.CallBackUtil;
import com.huihui.network.base.OkhttpUtil;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import okhttp3.Call;

public class GuideActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        testNet();
    }

    private void testNet() {
        testGet();
        testPost();
        testPut();
        testDelete();
        testUpload();
        testDownLoad();

    }

    private void testDownLoad() {
        OkhttpUtil.okHttpDownloadFile("url", new CallBackUtil.CallBackFile("fileDir","fileName") {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onProgress(float progress, long total) {
            }

            @Override
            public void onResponse(File response) {

            }
        });
    }

    private void testUpload() {
        File file = new File(Environment.getExternalStorageDirectory()+"/kwwl/abc.jpg");
        LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("title","title");
        OkhttpUtil.okHttpUploadFile("url", file, "image", OkhttpUtil.FILE_TYPE_IMAGE, paramsMap, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onProgress(float progress, long total) {

            }

            @Override
            public void onResponse(String response) {

            }
        });
    }

    private void testDelete() {
        String url = "https://www.baidu.com/";
        LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("title","title");
        OkhttpUtil.okHttpDelete(url, paramsMap, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(String response) {

            }
        });
    }

    private void testPut() {
        String url = "https://www.baidu.com/";
        LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("title","title");
        OkhttpUtil.okHttpPut(url, paramsMap, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(String response) {

            }
        });
    }

    private void testPost() {
        String url = "https://www.baidu.com/";
        LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("title","title");
        OkhttpUtil.okHttpPost(url, paramsMap, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(String response) {

            }
        });
    }

    private void testGet() {
        String url = "https://www.baidu.com/";
        OkhttpUtil.okHttpGet(url, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {}

            @Override
            public void onResponse(String response) {
                Log.d("kwwl",response);
            }
        });
    }


}
